package com.example.administrator.familfinalcialmanagement.ui.fragment;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.bean.UserInfoBean;
import com.example.administrator.familfinalcialmanagement.databinding.FragmentMyselfBinding;
import com.example.administrator.familfinalcialmanagement.ui.activity.AboutMeActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.LoginOutActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.MyInfoActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.MyMoneyActivity;
import com.example.administrator.familfinalcialmanagement.ui.activity.ToastActivity;
import com.example.administrator.familfinalcialmanagement.util.GlideUtil;
import com.example.administrator.familfinalcialmanagement.util.LogUtil;
import com.example.administrator.familfinalcialmanagement.util.SpUtils;
import com.example.administrator.familfinalcialmanagement.util.ToastUtil;

/**
 * Created by Administrator on 2019/3/26.
 */

public class MySelfFragment extends BaseLazyFragment {

    FragmentMyselfBinding binding;

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.fragment_myself, container, false);
        binding.setFragment(this);
        return binding.getRoot();
    }

    //懒加载，在界面消失的时候调用的方法，终结当前界面的操作
    @Override
    protected void onVisible() {

    }

    //懒加载，只有在界面显示的时候才会调用的方法，用来节约手机资源消耗
    @Override
    protected void lazyLoad() {
        UserInfoBean bean = (UserInfoBean) SpUtils.getBean( "user_info_bean" );
        if (bean != null) {
            if (!TextUtils.isEmpty( bean.headUrl )) {
                GlideUtil.setCircleMethod( getActivity(),bean.headUrl,binding.head );
            }

            if (!TextUtils.isEmpty( bean.name )) {
                binding.tvModuleName.setText( bean.name );
            }

            if (!TextUtils.isEmpty( bean.code )) {
                binding.tvModulePhone.setText( bean.code );
            }

            if (!TextUtils.isEmpty( bean.sagin )) {
                binding.tvModuleSchoolName.setText( bean.sagin );
            }

        }else{
            LogUtil.e( "sp无缓存" );
        }

        binding.linMyMonery.setOnClickListener(this);
        binding.linJizhang.setOnClickListener(this);
        binding.llModuleMyCommission.setOnClickListener(this);
        binding.llModuleAboutOur.setOnClickListener(this);
        binding.llModuleSet.setOnClickListener(this);
        binding.head.setOnClickListener(this);
        binding.llModuleName.setOnClickListener(this);
        binding.llModulePhone.setOnClickListener(this);
    }

    @Override
    public int setLayoutId() {
        return R.layout.fragment_index;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lin_myMonery:
                startActivity(new Intent(getActivity(),MyMoneyActivity.class));
                break;
            case R.id.lin_jizhang:
                startActivity(new Intent(getActivity(),ToastActivity.class));
                break;
            case R.id.llModulePhone:
                break;
            case R.id.llModuleAboutOur:
                startActivity(new Intent(getActivity(),AboutMeActivity.class));
                break;
            case R.id.llModuleSet:
                startActivity(new Intent(getActivity(),LoginOutActivity.class));
                break;
            case R.id.head:
                startActivity(new Intent(getActivity(),MyInfoActivity.class));
                break;
            default:
        }
    }



}